/************************************************************************
                                                                     
   Xceed Ultimate ListBox for Silverlight                                                                                                                                            
   Copyright (C) 2010 Xceed Software Inc.    
                                                                     
   This program is provided to you under the terms of the GNU General Public  
   License version 2 as published by the Free Software Foundation. 
        
   This program is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY, without even the implied warranty of 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License along 
   with this program, if not, write to the Free Software Foundation, Inc., 
   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

   This program can be provided to you by Xceed Software Inc. under a
   proprietary commercial license agreement for use in non-Open Source
   projects. Visit Xceed.com to find the commercial edition of 
   Xceed Ultimate ListBox for Silverlight.                                    
                                                                      
 **********************************************************************/

using System;

namespace Xceed.Silverlight.Data
{
  public abstract class AsyncIndexDataSourceProvider : IndexDataSourceProvider, IAsyncDataSourceProvider
  {
    #region Constructor

    protected AsyncIndexDataSourceProvider()
      : base()
    {
    }

    #endregion

    #region QueryRequestInterval Property

    public TimeSpan QueryRequestInterval
    {
      get
      {
        return m_queryRequestInterval;
      }
      set
      {
        m_queryRequestInterval = value;
      }
    }

    private TimeSpan m_queryRequestInterval = TimeSpan.Zero;

    #endregion

    #region BufferConfiguration Property

    public BufferConfiguration BufferConfiguration
    {
      get
      {
        return m_bufferConfiguration;
      }
      set
      {
        if( value != m_bufferConfiguration )
        {
          m_bufferConfiguration = value;
        }
      }
    }

    private BufferConfiguration m_bufferConfiguration = new DynamicBufferConfiguration();

    #endregion

    #region IsAsynchronous Internal Property

    internal sealed override bool IsAsynchronous
    {
      get
      {
        return true;
      }
    }

    #endregion

    #region IsCachingAllowed Internal Property

    internal override bool IsCachingAllowed
    {
      get
      {
        return true;
      }
    }

    #endregion

    #region IsBufferingAllowed Internal Property

    internal override bool IsBufferingAllowed
    {
      get
      {
        return true;
      }
    }

    #endregion

    protected abstract IAsyncResult BeginExecuteCountQuery(
      CountQueryParameters queryParameters,
      AsyncCallback callback,
      object state );

    protected abstract CountQueryResult EndExecuteCountQuery( IAsyncResult asyncResult );

    protected abstract IAsyncResult BeginExecuteDataQuery(
      DataQueryParameters queryParameters,
      AsyncCallback callback,
      object state );

    protected abstract DataQueryResult EndExecuteDataQuery( IAsyncResult asyncResult );

    protected abstract IAsyncResult BeginExecuteFindQuery(
      FindQueryParameters queryParameters,
      AsyncCallback callback,
      object state );

    protected abstract FindQueryResult EndExecuteFindQuery( IAsyncResult asyncResult );

    protected abstract IAsyncResult BeginExecuteGroupCountQuery(
      GroupCountQueryParameters queryParameters,
      AsyncCallback callback,
      object state );

    protected abstract GroupCountQueryResult EndExecuteGroupCountQuery( IAsyncResult asyncResult );

    protected abstract IAsyncResult BeginExecuteStatQuery(
      StatQueryParameters queryParameters,
      AsyncCallback callback,
      object state );

    protected abstract StatQueryResult EndExecuteStatQuery( IAsyncResult asyncResult );

    internal sealed override IAsyncResult BeginExecuteCountQueryIndexed(
      CountQueryParameters queryParameters,
      AsyncCallback callback,
      object state )
    {
      return this.BeginExecuteCountQuery( queryParameters, callback, state );
    }

    internal sealed override CountQueryResult EndExecuteCountQueryIndexed( IAsyncResult asyncResult )
    {
      return this.EndExecuteCountQuery( asyncResult );
    }

    internal sealed override IAsyncResult BeginExecuteDataQueryIndexed(
      DataQueryParameters queryParameters,
      AsyncCallback callback,
      object state )
    {
      return this.BeginExecuteDataQuery( queryParameters, callback, state );
    }

    internal sealed override DataQueryResult EndExecuteDataQueryIndexed( IAsyncResult asyncResult )
    {
      return this.EndExecuteDataQuery( asyncResult );
    }

    internal sealed override IAsyncResult BeginExecuteFindQueryIndexed(
      FindQueryParameters queryParameters,
      AsyncCallback callback,
      object state )
    {
      return this.BeginExecuteFindQuery( queryParameters, callback, state );
    }

    internal sealed override FindQueryResult EndExecuteFindQueryIndexed( IAsyncResult asyncResult )
    {
      return this.EndExecuteFindQuery( asyncResult );
    }

    internal sealed override IAsyncResult BeginExecuteGroupCountQueryIndexed(
      GroupCountQueryParameters queryParameters,
      AsyncCallback callback,
      object state )
    {
      return this.BeginExecuteGroupCountQuery( queryParameters, callback, state );
    }

    internal sealed override GroupCountQueryResult EndExecuteGroupCountQueryIndexed( IAsyncResult asyncResult )
    {
      return this.EndExecuteGroupCountQuery( asyncResult );
    }

    internal sealed override IAsyncResult BeginExecuteStatQueryIndexed(
      StatQueryParameters queryParameters,
      AsyncCallback callback,
      object state )
    {
      return this.BeginExecuteStatQuery( queryParameters, callback, state );
    }

    internal sealed override StatQueryResult EndExecuteStatQueryIndexed( IAsyncResult asyncResult )
    {
      return this.EndExecuteStatQuery( asyncResult );
    }
  }
}
